// 描述对象的形状 命名规范带一个I
interface IZuobiao {
  x: number,
  y: number,
  z?: number
}

let p: IZuobiao = {
  x: 20,
  y: 20,
  z: 39
}

// 接口定义函数
interface IPoinit {
  // 冒号左边表示函数参数 右边表示函数返回值
  (aa: number): IZuobiao
}


const getPoint: IPoinit = function (x) {
  return {
    x: x,
    y: 0
  }
}

let p1: IZuobiao = getPoint(11)
console.log(p1);


// 定义一个自定义的对象类型
type People = {
  name: string,
  age: number,
  sayHi: (msg: string) => void
}
// 利用接口定义一个类，这个类必须返回的是一个People类型的对象
interface IPerson {
  new (pname: string, age: number): People
}
interface IFn {
  (msg: string): void
}
const Person: IPerson = class {
  // 声明属性
  name: string
  age: number
  // (msg: string) => void是函数类型字面量的定义方式
  // sayHi: (msg: string) => void
  sayHi: IFn
  constructor(xingming: string, nianliang: number) {
    this.name = xingming
    this.age = nianliang
    this.sayHi = function (msg: string) {
      console.log(msg + this.name);
    }
  }
}


let zhangshan = new Person('zhangsan', 19)
console.log(zhangshan);
zhangshan.sayHi('你好')



// 定义一个Article类  这个类有（id数字 author字符串 publicDate字符串 comments数组）
// 比如这个类创建的对象长下面这个样子
// let wenzhang = {
//   id: 1,
//   author: 'zhangsan',
//   publicDate: '2022-07-11',
//   comments: [
//     '写的不错',
//     '干货'
//   ]
// }


interface IArticle {
  new (id: number, author: string, publicDate: string, comments: string[]): Object
}

const Article: IArticle = class {
  id: number
  author: string
  publicDate: string
  comments: string[]
  constructor(id: number, author: string, publicDate: string, comments: string[]) {
    this.id = id
    this.author = author
    this.publicDate = publicDate
    this.comments = comments
  }
}

let wenzhang = new Article(1, 'lisi', '2022-08-9', ['hello'])
console.log(wenzhang);




export { }